﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Drawing;

namespace OpenPhotoAlbum.Controls.PhotoProcessors
{
	public class Mosaic : Offset
	{
		private const int SIDE_LENGTH = 10;

		public override void ConfigureOffsetMatrix(Point[,] offsetMatrix, int width, int height)
		{
			for (int y = 0; y < height; y++)
			{
				for (int x = 0; x < width; x++)
				{
					int resultX = x - x % SIDE_LENGTH;
					int resultY = y - y % SIDE_LENGTH;
					if (x % SIDE_LENGTH == 0) { resultX += SIDE_LENGTH * 2; }
					if (y % SIDE_LENGTH == 0) { resultY += SIDE_LENGTH * 2; }

					if (resultX < 0) { resultX = 0; }
					else if (resultX > width - 1) { resultX = width - 1; }
					if (resultY <= 0) { resultY = 0; }
					else if (resultY > height - 1) { resultY = height - 1; }

					offsetMatrix[y, x] = new Point(resultX, resultY);
				}
			}
		}
	}

}
